package top.lyc829.mymusic.adapter

import android.content.Context
import android.content.res.Resources
import android.graphics.Color
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lzx.starrysky.SongInfo
import top.lyc829.mymusic.R
import top.lyc829.mymusic.databinding.ItemMusicListDialogBinding

/**
 * @Author lyc
 * @create 2021-07-26 19:34
 */
class MusicListDialogAdapter(context: Context) : BaseQuickAdapter<SongInfo, BaseViewHolder>(
    R.layout.item_music_list_dialog
) {
    private var currentSong: SongInfo? = null

    override fun convert(holder: BaseViewHolder, item: SongInfo) {
        val binding = ItemMusicListDialogBinding.bind(holder.itemView)
        binding.itemName.text = item.songName
        binding.itemAuthor.text = item.artist
        if (currentSong?.songId == item.songId) {
            binding.tipView.visibility = View.VISIBLE
            binding.itemName.setTextColor(context.getColor(R.color.pink))
            binding.itemAuthor.setTextColor(context.getColor(R.color.pink))
        } else {
            binding.tipView.visibility = View.GONE
            binding.itemName.setTextColor(context.getColor(R.color.listTextColor))
            binding.itemAuthor.setTextColor(context.getColor(R.color.listSubTextColor))
        }
    }

    fun updateCurrentSongInfo(songInfo: SongInfo, index: Int) {
        currentSong = songInfo
        notifyItemChanged(index)
    }

}